<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>{$data.name}</title>
    <link rel="stylesheet" href="__STATIC__assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="__STATIC__assets/module/admin.css?v=318"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        /** 数据表格中的select尺寸调整 */
        .layui-table-view .layui-table-cell .layui-select-title .layui-input {
            height: 28px;
            line-height: 28px;
        }

        .layui-table-view [lay-size="lg"] .layui-table-cell .layui-select-title .layui-input {
            height: 40px;
            line-height: 40px;
        }

        .layui-table-view [lay-size="lg"] .layui-table-cell .layui-select-title .layui-input {
            height: 40px;
            line-height: 40px;
        }

        .layui-table-view [lay-size="sm"] .layui-table-cell .layui-select-title .layui-input {
            height: 20px;
            line-height: 20px;
        }

        .layui-table-view [lay-size="sm"] .layui-table-cell .layui-btn-xs {
            height: 18px;
            line-height: 18px;
        }
        
        #tbImgTable + .layui-table-view .layui-table-body tbody > tr > td {
            padding: 0;
        }

        #tbImgTable + .layui-table-view .layui-table-body tbody > tr > td > .layui-table-cell {
            height: 48px;
            line-height: 48px;
        }

        .tb-img-circle {
            width: 26px;
            height: 26px;
            cursor: zoom-in;
            border-radius: 50%;
            border: 1px solid #dddddd;
        }

    </style>
</head>
<body onscroll="layui.admin.hideFixedEl();">
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格工具栏 -->
            <form class="layui-form toolbar table-tool-mini">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">通道名称:</label>
                        <div class="layui-input-inline">
                            <input name="game_name" class="layui-input" type="text" placeholder="请输入通道名称"/>
                            
                        </div>
                        </div>
                    <div class="layui-inline" style="padding-right: 110px;">
                        <button class="layui-btn icon-btn" lay-filter="tbBasicTbSearch" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                </div>
            </form>
            <!-- 数据表格 -->
            <table id="tbBasicTable" lay-filter="tbBasicTable"></table>
        </div>
    </div>
  
</div>


<!-- 表格操作列 -->
<script type="text/html" id="tbBasicTbBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    
   
</script>

<script type="text/html" id="dialogEditDialog1">
    <form id="dialogEditForm1" lay-filter="dialogEditForm1" class="layui-form model-form no-padding">
        <input name="id" type="hidden"/>
	    <input name="game_img" id="game_img" type="hidden"/>
        <div class="model-form-body" style="max-height: 530px;overflow-y: inherit;">
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">通道图标:</label>
                  <div class="layui-upload">
                  <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
                
                  </div>
            </div>
		
            
           	<div class="layui-form-item">
                <label class="layui-form-label layui-form-required">是否启用:</label>
                <div class="layui-input-block">
                    <select name="state" lay-verify="required" required>
                        <option value="1">启用</option>
                        <option value="0">不启用</option>
                    </select>
                </div>
            </div>
			
        </div>
        <div class="layui-form-item text-right model-form-footer">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="dialogEditSubmit1" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- js部分 -->
<script type="text/javascript" src="__STATIC__assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="__STATIC__assets/js/common.js?v=318"></script>
<script>
    layui.use(['layer', 'form','laytpl','admin','table', 'util', 'dropdown','baseTable','upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var dropdown = layui.dropdown;
        var laytpl = layui.laytpl;
        var admin = layui.admin;
        var upload = layui.upload;
        /* 渲染表格 */
        var insTb = table.render({
            elem: '#tbBasicTable',
            url: "game_list",
            page: true,
            limit: 15,
            cellMinWidth: 100,
            cols: [[
                {title: '通道图标', templet: function (d) {
                        var url = '../__STATIC__assets/uploads/'+d.game_img || '----';
                        return '<img data-index="' + (d.LAY_INDEX - 1) + '" src="' + url + '" class="tb-img-circle" tb-img alt=""/>';
                    }, align: 'center', width: 100, unresize: true
                },
                {field: 'game_name', title: '通道名称', align: 'center',width:300},
                {field: 'game_dm', title: '通道代码', align: 'center',width:150},
                {field: 'state', title: '通道状态', templet: function (d) {
                        var strs = {
                            1:'<span class="layui-badge layui-badge-green">通道已启用</span>',
                            0:'<span class="layui-badge layui-badge-gray">通道未启用</span>'
                        };
                        return strs[d.state];
                    }, align: 'center',width:150
                },
                {field: 'by_pay', title: '本月总收', align: 'center',width:150},
                {field: 'sy_pay', title: '上月总收', align: 'center',width:150},
                {title: '操作', toolbar: '#tbBasicTbBar', align: 'center', minWidth: 80}
            ]]
        });

        /* 表格搜索 */
        form.on('submit(tbBasicTbSearch)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}});
            return false;
        });
        
        

        /* 表格工具条点击事件 */
        table.on('tool(tbBasicTable)', function (obj) {
            var data = obj.data; // 获得当前行数据
            var layEvent = obj.event;
            if (obj.event === 'edit') { // 修改
                showMode(data);
            }
            dropdown.hideAll();
        });
        
        
        
        function showMode(mData){
			admin.open({
                type: 1,
                title: "编辑",
				area: ['640px', '410px'],
                content: $('#dialogEditDialog1').html(),
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    form.val('dialogEditForm1',mData);
                    form.render(null, 'dialogEditForm1');
                    
                    // 表单提交事件
                    form.on('submit(dialogEditSubmit1)', function (data) {
						var loadIndex = layer.load(2);
                        $.post('game_save', data.field, function (res) {
                            layer.close(loadIndex);
                            if (0 != res.code) {                                
                                layer.msg(res.msg, {icon: 1});
                                insTb.reload({page: {curr: 1}});
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'json');
                        return false;
                    });
                    
                   upload.render({
                          elem: '#test8'
                          ,url: 'game_upload' //改成您自己的上传接口
                          ,auto: true
                          ,done: function(res){
                             if(res.code==1){
                                 layer.msg('上传成功');
                                 $('#game_img').val(res.msg);
                             }else{
                                 layer.msg(res.msg);
                             }
                          }
                        }); 
                    

                }
            });
		}
        
	
        
        /* 点击图片放大 */
        $(document).off('click.tbImg').on('click.tbImg', '[tb-img]', function () {
            var imgList = table.cache['tbBasicTable'].map(function (d) {
                return {
                    alt: d.game_name,
                    src: '../__STATIC__assets/uploads/'+d.game_img || '-----'
                }
            });
            layer.photos({photos: {data: imgList, start: $(this).data('index')}, shade: .1, closeBtn: true});
        });

   

    });
</script>
</body>
</html>